﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace myFinance.Controls
{
    public partial class AddFromDefinedExpence : UserControl
    {
        public AddFromDefinedExpence()
        {
            InitializeComponent();

            var c = new AddExpence();
            c.Top = 37;
            c.Left = 4;
            this.Controls.Add(c);

            this.cbKnownExpence.DataSource = DAL.DALFactory.GetDAL<DAL.SqlCeDAL>().GetKnownExpenceIdAndNames();
            this.cbKnownExpence.ValueMember = "Key";
            this.cbKnownExpence.DisplayMember = "Value";

            this.cbKnownExpence.Focus();
        }

        public Entity.IExpence GetExpence()
        {
            return (Entity.IExpence)this.Controls[0];
        }

        private void cbKnownExpence_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.cbKnownExpence.SelectedValue == null) return;

            var expence =
                DAL.DALFactory.GetDAL<DAL.SqlCeDAL>()
                    .GetKnownExpence(this.cbKnownExpence.SelectedValue.ToString().Trim());




            //var displayicnExpence = (Entity.IExpence)this.Controls[0];
            //displayicnExpence.Amount = expence.Amount;
            //displayicnExpence.CategoryID = expence.CategoryID;
            //displayicnExpence.Description = expence.Description;
            //displayicnExpence.LocationID = expence.LocationID;
        }
    }
}
